from pydantic import BaseModel, Field
from datetime import datetime
from typing import Optional

class ClassroomBase(BaseModel):
    classroom_code: str = Field(..., description="教室编码（如：10101）", max_length=10)
    classroom_name: str = Field(..., description="教室名称", max_length=50)
    building_no: int = Field(..., description="教学楼编号：1-主教学楼", ge=1, le=10)
    floor_no: int = Field(..., description="楼层：1-4层", ge=1, le=10)
    room_no: int = Field(..., description="教室编号：1-20", ge=1, le=50)
    capacity: int = Field(..., description="容纳人数", ge=1)
    room_type: int = Field(..., description="教室类型：1-普通教室 2-实验室 3-多媒体教室 4-音乐教室 5-美术教室")
    status: int = Field(1, description="状态：0-停用 1-启用")

class ClassroomCreate(ClassroomBase):
    """创建教室时使用的模型"""
    pass

class ClassroomUpdate(BaseModel):
    """更新教室时使用的模型"""
    classroom_code: Optional[str] = None
    classroom_name: Optional[str] = None
    building_no: Optional[int] = None
    floor_no: Optional[int] = None
    room_no: Optional[int] = None
    capacity: Optional[int] = None
    room_type: Optional[int] = None
    status: Optional[int] = None

class Classroom(ClassroomBase):
    id: int
    create_time: Optional[datetime] = Field(None, description="创建时间")
    update_time: Optional[datetime] = Field(None, description="更新时间")
    
    class Config:
        from_attributes = True